<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<c:set var="url" value="${pageContext.request.contextPath}/" />
<link rel="stylesheet" href="${url }plugins/select2/select2.min.css">
<script src="${url }plugins/select2/select2.full.min.js"></script>
<script type="text/javascript">
$(function() {
	init();
});

function init(){
	var addIp =$("#addIp").val();
	$.ajax({
		type:"POST",
		url: path+'collect/getBeatInfo',
		data:{ip:addIp,beatName:'filebeat'},
		success: function(result){
			if(result.result.filebeat){
				$("#nodeTbody").html("");
				for(var i = 0;i<result.result.filebeat.parameter.list.length;i++){
					var appendStr =" <tr><td>"+result.result.filebeat.parameter.list[i].path+"</td>";
					appendStr+="<td>"+result.result.filebeat.parameter.list[i].name+"</td><td>"
					appendStr+=result.result.filebeat.parameter.list[i].analyze+"</td>";
					appendStr+="<td>"+result.result.filebeat.parameter.list[i].desc+"</td>";
					appendStr+="<td><a href='#' title='删除' onclick='deleteFileBeatInfo(\""+result.result.filebeat.parameter.list[i].path+"\",\""+result.result.filebeat.parameter.list[i].name+"\",\""+result.result.filebeat.parameter.list[i].analyze+"\",\""+result.result.filebeat.parameter.list[i].desc+"\")'><i class='fa fa-play text-red'></i>删除</a></td></tr>";
					$("#nodeTbody").append(appendStr);
				}
			}
		}
	}); 
}

function deleteFileBeatInfo(upath,name,analyze,desc){
	$("#rmPath").val(upath);
	$("#rmName").val(name);
	$("#rmAnalyze").val(analyze);
	$("#rmDesc").val(desc);
	$.ajax({
		type:"POST",
		url: path+'collect/deleteFileBeatInfo',
		data:$('#removeFileBeat').serialize(),
		success: function(result){
			if(result){
				alert('删除成功');
				init();
			}
		}
	});
}

function addBeat(){
	$("#rmIp").val($("#addIp").val());
	$.ajax({
		cache:false,
		async:false,
		type:"POST",
		url: path
		+"collect/addFileBeat",
		data:$('#addForm').serialize(),
		success: function(result){
			if(result){
				alert("添加成功");
				init();
			}
		}
	});
}
</script>
<div class="box box-primary">
	<div class="box-header with-border">
		<h3 class="box-title">FileBeat / </h3>
		<!-- /.box-tools -->
	</div>
	
  <!-- /.box-header -->
  <div class="box-body no-padding">
    <div class="table-responsive mailbox-messages">
      <table class="table table-bordered">
      	<thead>
      		<tr style="background-color: #f9f9f9;">
      		<th>路径</th>
      		<th>日志名称</th>
      		<th>解析规则</th>
      		<th>描述</th>
      		<th>操作</th>
      		</tr>
      	</thead>
        <tbody id="nodeTbody">

        </tbody>
      </table>
      <!-- /.table -->
    </div>
    <!-- /.mail-box-messages -->
  </div>
  <!-- /.box-body -->
  
</div>

<div class="box box-info">
<form id="addForm">
<!-- /.box-header -->
  <div class="box-body form-horizontal">
  	<div class="form-group">
       <label for="inputEmail3" class="col-sm-2 control-label">文件或目录</label>
       <div class="col-sm-3">
         <input type="text" class="form-control" id="path" name="path">
       </div>
     </div>
  	<div class="form-group">
       <label for="inputEmail3" class="col-sm-2 control-label">日志名称</label>
       <div class="col-sm-3">
         <input type="text" class="form-control" id="name" placeholder="日志名称" name="name">
       </div>
     </div>
  	<div class="form-group">
       <label for="inputEmail3" class="col-sm-2 control-label">解析规则</label>
       <div class="col-sm-3">
         <select name="analyze" class="form-control select2" id="analyze">
			<option value="主机管控日志解析">主机管控日志解析</option>
			<option value="OA日志解析">OA日志解析</option>
		</select>
       </div>
     </div>
     <div class="form-group">
       <label for="inputEmail3" class="col-sm-2 control-label">描述</label>
       <div class="col-sm-5">
         <input type="text" class="form-control" id="desc" placeholder="描述" name="desc">
       </div>
     </div>
      <div class="box-footer">
        <a type="button" class="btn btn-info"  onclick="addBeat()">添加</a>
        <a href="javascript:linkByDom('local-list','${url }collect/getBeatList');" class="btn btn-default">取消</a>
     </div>
  </div>
	<input type="hidden" value="${ip }" id="addIp" name="ip"/>		            
  </form>
</div>
<form id="removeFileBeat">
	<input type="hidden" id="rmPath" name="path" />
	<input type="hidden" id="rmName" name="name" />
	<input type="hidden" id="rmAnalyze" name="analyze" />
	<input type="hidden" id="rmDesc" name="desc" />
	<input type="hidden" id="rmIp" name="ip" value="${ip }">
</form>
